<!DOCTYPE HTML PUBdtC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>oscP5 : : OscP5 : : plug ( )</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stylesheet.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
document.getElementsByTagName('html')[0].className = 'isjs';

function toggle(dt) 
{ 
  var display, dd=dt; 
  /* get dd */ 
  do{ dd = dd.nextSibling } while(dd.tagName!='DD'); 
  toOpen =!dd.style.display; 
  dd.style.display = toOpen? 'block':'' 
  dt.getElementsByTagName('span')[0].innerHTML 
    = toOpen? '-':'+' ; 
} 
</script>
</head>
<body>
<div id="container">
	<div id="header">
	<a href="./index.htm"><img src="./docuImages/title.jpg" /></a>
	</div>
	<div class="content">
	<h1><a href="index.htm">oscP5</a> / <a href="OscP5_class_OscP5.htm">OscP5</a> / plug( )</h1>
		<div class="separator">
		<dl><dt class="key">name</dt><dd class="value">plug ( )</dd></dl>
		</div>
		<dl><dt class="key">description</dt><dd class="value">osc messages can be automatically forwarded to a specific method of an
 object. the plug method can be used to by-pass parsing raw osc messages -
 this job is done for you with the plug mechanism. you can also use the
 following array-types int[], float[], String[]. (but only as on single
 parameter e.g. somemethod(int[] theArray) {} ).&nbsp;</dd></dl>
		
		<div class="toggleList example">
			<dl><dt onclick="toggle(this)"><span>+</span>Examples</dt>
			<dd><pre>/**
 * oscP5plug by andreas schlegel
 * example shows how to use the plug service with oscP5.
 * the concept of the plug service is, that you can
 * register methods in your sketch to which incoming 
 * osc messages will be forwareded automatically without 
 * having to parse them in the oscEvent method.
 * that a look at the example below to get an understanding
 * of how plug works.
 * oscP5 website at http://www.sojamo.de/oscP5
 */

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

void setup() {
  size(400,400);
  frameRate(25);
  /* start oscP5, listening for incoming messages at port 12000 */
  oscP5 = new OscP5(this,12000);
  
  /* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
   * an ip address and a port number. myRemoteLocation is used as parameter in
   * oscP5.send() when sending osc packets to another computer, device, 
   * application. usage see below. for testing purposes the listening port
   * and the port of the remote location address are the same, hence you will
   * send messages back to this sketch.
   */
  myRemoteLocation = new NetAddress("127.0.0.1",12000);
  
  /* osc plug service
   * osc messages with a specific address pattern can be automatically
   * forwarded to a specific method of an object. in this example 
   * a message with address pattern /test will be forwarded to a method
   * test(). below the method test takes 2 arguments - 2 ints. therefore each
   * message with address pattern /test and typetag ii will be forwarded to
   * the method test(int theA, int theB)
   */
  oscP5.plug(this,"test","/test");
}


public void test(int theA, int theB) {
  println("### plug event method. received a message /test.");
  println(" 2 ints received: "+theA+", "+theB);  
}


void draw() {
  background(0);
}


void mousePressed() {
  /* createan osc message with address pattern /test */
  OscMessage myMessage = new OscMessage("/test");
  
  myMessage.add(123); /* add an int to the osc message */
  myMessage.add(456); /* add a second int to the osc message */

  /* send the message */
  oscP5.send(myMessage, myRemoteLocation); 
}


/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
  /* with theOscMessage.isPlugged() you check if the osc message has already been
   * forwarded to a plugged method. if theOscMessage.isPlugged()==true, it has already 
   * been forwared to another method in your sketch. theOscMessage.isPlugged() can 
   * be used for double posting but is not required.
  */  
  if(theOscMessage.isPlugged()==false) {
  /* print the address pattern and the typetag of the received OscMessage */
  println("### received an osc message.");
  println("### addrpattern\t"+theOscMessage.addrPattern());
  println("### typetag\t"+theOscMessage.typetag());
  }
}
</pre></dd>
			</dl>
		</div>
		
		<div class="separator">
		<dl><dt class="key">Syntax</dt><dd class="value"><pre>plug(theObject, theMethodName, theAddrPattern, theTypeTag);
plug(theObject, theMethodName, theAddrPattern);
</pre></dd></dl>
		</div>
		<div class="separator">
		
   <dl><dt class="key">parameters</dt><dd class="value"><span class="parameters">theObject</span><span class="parameters">Object, can be any Object</span><span class="clear">&nbsp;</span></dd>
<dd class="value"><span class="parameters">theMethodName</span><span class="parameters">String, the method name an osc message should be
 forwarded to</span><span class="clear">&nbsp;</span></dd>
<dd class="value"><span class="parameters">theAddrPattern</span><span class="parameters">String, the address pattern of the osc message</span><span class="clear">&nbsp;</span></dd>
<dd class="value"><span class="parameters">theTypeTag</span><span class="parameters">String</span><span class="clear">&nbsp;</span></dd>
</dl>
		<br /><br />
		</div>
		<div class="separator">
		<dl><dt class="key">Returns</dt><dd class="value">None</dd></dl>

		</div>
		<div class="separator">
		<dl><dt class="key">Usage</dt><dd class="value">Application</dd></dl>
		</div>
		<div class="separator">
		<dl><dt class="key">Related</dt><dd class="value"><ul></ul></dd></dl>
		</div>
	</div>
	<div id="footer">
<p>by andreas schlegel (<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/" target="_blank">cc</a>) 2007, <a href="http://www.sojamo.de" target="_blank">sojamo</a>.</p>
</div>

</div>
</body>
</html>